from django.db import models


# Create your models here.

class Department(models.Model):
    """部门表"""
    title = models.CharField(verbose_name="部门标题", max_length=32)
    def __str__(self):
        return self.title

class Userinfo(models.Model):
    """员工表"""
    name = models.CharField(max_length=32, verbose_name="姓名")
    password = models.CharField(max_length=64, verbose_name="密码")
    age = models.IntegerField(verbose_name="年龄")
    account = models.DecimalField(verbose_name="账户余额", max_digits=10, decimal_places=2, default=0)
    # create_time = models.DateTimeField(verbose_name="入职时间")
    create_time = models.DateField(verbose_name="入职时间")
    # 无约束
    # depart_id = models.BigIntegerField(verbose_name='部门id')
    # 有约束
    # to 与哪张表关联
    # to_field 表中哪一列关联
    # 写的depart，django会自动生成depart_id加上后缀
    depart = models.ForeignKey(verbose_name='部门', to=Department, to_field='id', on_delete=models.CASCADE)
    # on_delete=models.CASCADE 级联删除
    # on_delete=models.SET_NULL允许为空，需打开null=True,blank=True
    # 在django中做的约束
    gender_choices = (
        (1, '男'),
        (2, '女')
    )
    gender = models.SmallIntegerField(verbose_name='性别', choices=gender_choices)

class PretyNum(models.Model):
    """靓号表"""
    mobile = models.CharField(max_length=11, verbose_name='手机号')
    # 允许字段为空加上这两参数null=True,blank=True
    price = models.IntegerField(verbose_name='价格', default=99)
    level_choice = (
        (1, '1级'),
        (2, '2级'),
        (3, '3级'),
        (4, '4级'),
    )
    level = models.SmallIntegerField(verbose_name='靓号等级', default=1, choices=level_choice)
    status_choice = (
        (1, '已占用'),
        (2, '未启用')
    )
    status = models.SmallIntegerField(verbose_name='号码状态', choices=status_choice, default=2)

class Admin(models.Model):
    """管理员"""
    username = models.CharField(verbose_name='用户名',max_length=32)
    password = models.CharField(verbose_name='密码',max_length=64)

    def __str__(self):
        return self.username


class Task(models.Model):
    """任务"""
    level_choice = (
        (1,'紧急'),
        (2,'加急'),
        (3,'一般')
    )
    level = models.SmallIntegerField(verbose_name='任务级别',choices=level_choice)
    title = models.CharField(verbose_name='标题',max_length=64)
    detail = models.TextField(verbose_name='详细信息')
    user = models.ForeignKey(to=Admin,verbose_name="负责人",on_delete=models.CASCADE)


class Order(models.Model):
    """订单"""
    oid = models.CharField(verbose_name='订单号',max_length=64)
    title = models.CharField(verbose_name='商品名称',max_length=32)
    price = models.IntegerField(verbose_name='价格')
    status_choice = (
        (1,'待支付'),
        (2,'已支付')
    )
    status = models.SmallIntegerField(verbose_name='支付状态',choices=status_choice,default=1)
    admin = models.ForeignKey(to=Admin,verbose_name='下单人',on_delete=models.CASCADE)

class Boss(models.Model):
    """ 老板（form用于文件上传）"""
    name = models.CharField(verbose_name='姓名',max_length=32)
    age = models.IntegerField(verbose_name='年龄')
    img = models.CharField(verbose_name="头像",max_length=128)

class City(models.Model):
    """ 城市（用于modelform文件上传）"""
    name = models.CharField(verbose_name='城市名称',max_length=32)
    count = models.IntegerField(verbose_name='人口')
    img = models.FileField(verbose_name="Logo",max_length=128,upload_to='city/')